<?php
/**
 * Created by PhpStorm.
 * User: gxk
 * Date: 2019/4/15
 * Time: 16:46
 */

use Middleware\LoginMiddleware;

defined('slim') or exit('请求不合法');

//添加登陆中间件
$app->group('',function () use ($app){
    //首页
    $app->get('/', '\Index\IndexController:index');
    //聊天插入数据库
    $app->post('/chat', '\Index\ChatController:chat');
    //获取聊天列表
    $app->get('/chatlist', '\Index\ChatController:chatlist');
    //获取用户列表
    $app->get('/userList', '\Index\IndexController:userList');
})->add(Middleware\LoginMiddleware::class);
//测试路由
$app->get('/test', '\Index\IndexController:test');

//登陆
$app->get('/login', '\Index\LoginController:index');
$app->post('/login', '\Index\LoginController:login');










$app->get('/ceshi', '\Index\IndexController:ceshi');
$app->get('/ceshi1', '\Index\IndexController:ceshi1');
$app->get('/tcp', '\Index\IndexController:test_swoole_tcp');
//$app->get('/', function(){
//    var_dump(99999999999);
//});

//redis测试
$app->get('/redis','\Index\IndexController:redis');
//$app->get('/swoole','\Index\IndexController:swoole');
//$app->get('/swooleclient','\Index\IndexController:swoole_socket_client');
//$app->get('/ceshi', function ($request,$response,$args){
//    $response->write('hello world');
//});
////resque测试
//$app->get('/resque', '\Index\IndexController:resque');
//添加去掉最后一个斜线的中间件
//$app->add(function($request, $response, $next){
//    $uri = $request->getUri();
//    $path = $uri->getPath();
//    if ($path != '/' && substr($path, -1) == '/') {
//        $uri = $uri->withPath(substr($path, 0, -1));
//        return $response->withRedirect((string)$uri, 301);
//    }
//    return $next($request, $response);
//});
//添加登陆中间件
//$app->add(new Middleware\LoginMiddleware());
//中间件测试
$app->get('/middleware/{name}', '\Index\IndexController:middleware');
